package com.lc.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * 验证码配置类
 */
@Configuration
public class CaptchaConfig {

    @Bean
    public DefaultKaptcha defaultKaptcha(){
        //验证码生成器
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        //配置
        Properties properties = new Properties();

        //图片边框
        properties.setProperty("kaptcha.border","yes");
        //图片边框颜色
        properties.setProperty("kaptcha.border.color","105,179,90");
        //图片边框厚度
        properties.setProperty("kaptcha.border.thickness","1");
        //验证码
        properties.setProperty("kaptcha.session.key","code");
        //图片字体颜色
        properties.setProperty("kaptcha.textproducer.font.color","blue");
        //图片字体样式
        properties.setProperty("kaptcha.textproducer.font.names","宋体,楷体,微软雅黑");
        //图片字体大小
        properties.setProperty("kaptcha.textproducer.font.size","30");
        //字符长度
        properties.setProperty("kaptcha.textproducer.char.length","4");
        //文字间隔
        properties.setProperty("kaptcha.textproducer.char.space","4");
        //图片宽
        properties.setProperty("kaptcha.image.width","100");
        //图片高
        properties.setProperty("kaptcha.image.height","40");
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
